<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>惰性函数与性能</title>
</head>
<body>
    <button id="btn">点击</button>
    <script>
        var oBtn = document.getElementById('btn')
        function foo(){
            console.log(this)
        }
        // function addEvent (obj, type, fn){
        //     if(obj.addEventListerer){
        //         obj.addEventListerer(type, fn, false)
        //     }else if(obj.attachEvent){
        //         obj.attachEvent('on' + type, fn)
        //     }else{
        //         obj['on' + type ] = fn
        //     }
        // }
        function addEvent (obj, type, fn){
            if(obj.addEventListerer){
                addEvent = obj.addEventListerer(type, fn, false)
            }else if(obj.attachEvent){
                addEvent = obj.attachEvent('on' + type, fn)
            }else{
                addEvent = obj['on' + type ] = fn
            }
            return addEvent
        }
        addEvent(oBtn, 'click', foo)
    </script>
</body>
</html>